package com.cy.health.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ModelViewController {
    // http://localhost:80/doModelAndView01/
    @RequestMapping("/doModelAndView01")
    public String doModelAndView01(Model model) {
        model.addAttribute("username", "jack");
        model.addAttribute("state",true);
        return "view";
    }

    // localhost/doModelAndView
    @RequestMapping("/doModelAndView02")
    // 这里的ModelAndView是Model对象和view对象的一个合体
    public ModelAndView doModelAndView02(ModelAndView mv) {
        mv.addObject("username","charles");
        mv.addObject("state", "good");
        mv.setViewName("view");
        return mv;
    }

    // localhost/doModelAndView03
    @RequestMapping("/doModelAndView03")
    public ModelAndView doModelAndView03(ModelAndView mv) {
        List<String> list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("深圳");
        list.add("深圳");
        mv.addObject("cities", list);
        mv.addObject("rows", new Integer[]{1,2,3,4});
        mv.setViewName("view");
        return mv;
    }
}
